<?php
$featureName = '提现';

?>
@extends('admin.formLayout')
@if(isset($id))
    @section('title','编辑'.$featureName)
@section('barName','编辑'.$featureName)
@else
    @section('title','添加'.$featureName)
@section('barName','添加'.$featureName)
@endif
@section('content')
    <form class="layui-form" @if(!isset($id)) action="{{route($routePrefix.'.add')}}" @else action="{{route($routePrefix.'.edit',['id'=>$id])}}" @endif method="post">
        <div class="layui-tab" lay-filter="posts">
            <ul class="layui-tab-title">
                <li class="layui-this">基本信息</li>
            </ul>
            <div class="layui-tab-content">
                <div class="layui-tab-item layui-show">
                    <div class="layui-row">
                            <div class="layui-col-md8">
                                {{csrf_field()}}
                                @if(isset($id))
                                    <input type="hidden" name="id" value="{{$id}}">
                                @endif

                                <div class="layui-form-item">
                                    <label class="layui-form-label">用户<span style="color:red">*</span></label>
                                    <div class="layui-input-block">
                                        <ul id="step1container">
                                            @if(isset($model)&&$model->combo)
                                                <li>
                                                    {{$model->combo->title}}
                                                </li>
                                            @endif

                                        </ul>
                                        <input lay-verify="required" type="hidden" name="member_id" value="{{$model->combo_id or ''}}"/>
                                    </div>
                                    <div class="layui-input-block">
                                        <button class="layui-btn layui-btn-xs layui-btn-primary" id="step1" type="button"><i class="layui-icon">&#xe654;</i>选择用户</button>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">金额(￥)<span style="color:red">*</span></label>
                                    <div class="layui-input-block">
                                        <input type="number" name="price" value="@if(old('price')){{old('price')}}@else{{$model->price or ''}}@endif"  class="layui-input" style="width:100px;"  min="0" placeholder="0.00" max="0" lay-verify="required" />
                                    </div>
                                    <div class="layui-input-block" id="canWithdrawMoney">
                                        <p style="color:red">可提现金额：￥0.00</p>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">银行卡号</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="bank_id" value="@if(old('bank_id')){{old('bank_id')}}@else{{$model->bank_id or ''}}@endif"  class="layui-input"   min="0"   />
                                    </div>
                                    <div class="layui-input-block">
                                        <p id="bankCardImg"></p>
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">银行卡姓名</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="username" value="@if(old('username')){{old('username')}}@else{{$model->username or ''}}@endif"  class="layui-input"  />
                                    </div>
                                </div>
                                <div class="layui-form-item layui-form-text">
                                    <label class="layui-form-label">备注</label>
                                    <div class="layui-input-block">
                                        <textarea name="desc"  placeholder="请输入备注..." class="layui-textarea">@if(old('desc')){{old('desc')}}@else{{$model->desc or ''}}@endif</textarea>
                                    </div>
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" lay-submit="" lay-filter="form">立即提交</button>
                                    <button type="button"  onclick="javascript:location.href='{{route($routePrefix)}}'" class="layui-btn layui-btn-primary">返回</button>
                                </div>
                            </div>
                    </div>
                </div>
            </div>
        </div>

    </form>
@endsection
@section('script')

    <script>
        var combo = {};

        layui.use(['element','form','layer','jquery','laydate'], function(){
            var element = layui.element;
            var form = layui.form;
            var layer = layui.layer;
            var $ = layui.jquery;
            var laydate = layui.laydate;
            //选择套餐
            $(document).on('click','#step1',function () {
                layer.open({
                    type: 2,
                    title: '选择套餐',
                    shadeClose: true,
                    shade: 0.8,
                    area: ['90%', '100%'],
                    resize:true,
                    content: '{{route($routePrefix.'.memberList')}}', //iframe的url
                    success:function () {
                        combo = {}
                    },
                    end:function () {
                        if(combo&&combo.id!=undefined){
                            str = '<li>';
                            str +='<p>'+combo.nickname+'</p>'
                            str +='</li>';
                            $('#step1container').html(str);
                            $('#step1').text('重新选择用户');
                            $('[name=member_id]').val(combo.id);
                            var max = combo.wallet_push_money;
                            $('#canWithdrawMoney>p').html('可提现金额：￥'+max);
                            $('[name=price]').attr('max',max);
                            if(max<$('[name=price]').val())$('[name=price]').val(max);
                        }
                    }
                });
            })


            form.on('radio(type)', function(data){
                //console.log(data.elem); //得到checkbox原始DOM对象
//                console.log(data.elem.checked); //是否被选中，true或者false
//                console.log(data.value); //复选框value值，也可以通过data.elem.value得到
                var value   =  data.value;
                var checked = data.elem.checked;
                if(value=={{\App\Http\Controllers\Admin\Business\Service\ComboActivities::REBATE}}&&checked){
                    $('.type_cascade').hide();
                    $('#rebate').show();
                }else if(value=={{\App\Http\Controllers\Admin\Business\Service\ComboActivities::REDUCE}}&&checked){
                    $('.type_cascade').hide();
                    $('#reduce').show();
                }
                //console.log(data.othis); //得到美化后的DOM对象
            });
            form.on('radio(rate)', function(data){
                //console.log(data.elem); //得到checkbox原始DOM对象
//                console.log(data.elem.checked); //是否被选中，true或者false
//                console.log(data.value); //复选框value值，也可以通过data.elem.value得到
                var value   =  data.value;
                var checked = data.elem.checked;
                if(value==2&&checked){
                    $('.rate_cascade').show();
                }else{

                    $('.rate_cascade').hide();
                }
                //console.log(data.othis); //得到美化后的DOM对象
            });
            $(document).on('keyup','[name=bank_id]',function () {
                var _val = $(this).val();
                if(_val.length==16||_val.length==19){
                    $.ajax({
                        type: "get",
                        url: "{{route('api.getBankInfo')}}?bank_id="+_val,
                        dataType: "json",
                        //jsonp: "callback",//传递给请求处理程序或页面的，用以获得jsonp回调函数名的参数名(一般默认为:callback)
                        //jsonpCallback:"flightHandler",//自定义的jsonp回调函数名称，默认为jQuery自动生成的随机函数名，也可以写"?"，jQuery会自动为你处理数据
                        success: function(e){
                            if(e.validated==true){
                                var bank=e.bank;
                                var cardType = e.cardType;
                                var stat = e.stat;
                                var str = '<img src="https://apimg.alipay.com/combo.png?d=cashier&t='+bank+'"/>';
                                $('#bankCardImg').html(str);
                            }else{
                                $('#bankCardImg').html('');
                            }
                        },
                        error: function(e){
                            console.log(e);

                            //alert('fail');
                        }
                    });
                }else{
                    $('#bankCardImg').html('');
                }

            })
            if($('[name=bank_id]').val()){
                $('[name=bank_id]').trigger('keyup');
            }
            form.on('submit(*)',function(data){
                console.log(data);
                return false;
            });
            //一些事件监听
            element.on('tab(posts)', function(data){
            });
            @if (count($errors) > 0)
                @foreach ($errors->all() as $error)
                    layer.msg('{{$error}}',{'icon':2});
                    @break
                @endforeach
            @endif

        });
    </script>
@endsection